<template>
  <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
      <el-form-item label="单据号" prop="serialNo">
        <el-input v-model="form.serialNo" placeholder="" disabled />
      </el-form-item>
      <el-form-item label="关联单据号" prop="bizBillId">
        <el-input v-model="form.bizBillId" placeholder="请输入关联单据号" disabled>
          <el-button slot="append" @click="handleSelectBiz" :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true">选择</el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="业务类型" prop="bizType">
        <el-select v-model="form.bizType" placeholder="请选择业务类型" clearable filterable>
          <el-option v-for="dict in bizTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="客户" prop="customerId">
        <el-select v-model="form.customerId" placeholder="请选择客户" clearable filterable :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true">
          <el-option v-for="dict in customerIdOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="parseInt(dict.dictValue)"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="合同编号" prop="contractId">
        <el-input v-model="form.contractId" placeholder="" disabled />
      </el-form-item>
      <el-form-item label="合同类型" prop="contractType" disabled>
        <el-select v-model="form.contractType" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in contractTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="applyUser">
        <el-select v-model="form.applyUser" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in applyUserOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请日期" prop="applyTime">
        <el-date-picker clearable size="small" v-model="form.applyTime" type="date" value-format="yyyy-MM-dd" placeholder="" disabled>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请状态" prop="applyStatus">
        <el-select v-model="form.applyStatus" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in applyStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核人" prop="auditUser">
        <el-select v-model="form.auditUser" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in auditUserOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核日期" prop="auditTime">
        <el-date-picker clearable size="small" v-model="form.auditTime" type="date" value-format="yyyy-MM-dd" placeholder="" disabled>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="form.auditStatus" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in auditStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核意见" prop="auditComment">
        <el-input v-model="form.auditComment" type="textarea" placeholder="" disabled />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true" />
      </el-form-item>
      <el-form-item label="单据状态" prop="billStatus">
        <el-select v-model="form.billStatus" placeholder="" clearable filterable disabled>
          <el-option v-for="dict in billStatusOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
        </el-select>
      </el-form-item>
      <el-divider content-position="center">出库申请明细信息</el-divider>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="primary" icon="el-icon-plus" size="mini" @click="handleAddWmsOutWarehouseApplyDetail">添加</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteWmsOutWarehouseApplyDetail">删除</el-button>
        </el-col>
      </el-row>
      <el-table :data="wmsOutWarehouseApplyDetailList" :row-class-name="rowWmsOutWarehouseApplyDetailIndex" @selection-change="handleWmsOutWarehouseApplyDetailSelectionChange" ref="wmsOutWarehouseApplyDetail">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="序号" align="center" prop="index" width="50" />
        <el-table-column label="物料" prop="materialName" width="300">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.materialName'" :rules="rules.materialName">
              <el-input v-model="scope.row.materialName" placeholder="请选择物料" disabled>
                <el-button slot="append" @click="handleSelectMaterial(scope.$index)" :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true">选择</el-button>
              </el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="仓库" prop="warehouseId" width="150">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.warehouseId'">
              <el-select v-model="scope.row.warehouseId" placeholder="" disabled>
                <el-option v-for="dict in warehouseIdOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue"></el-option>
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="库区" prop="whRegionId" width="150">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.whRegionId'">
              <el-select v-model="scope.row.whRegionId" placeholder="" disabled>
                <el-option v-for="dict in scope.row.whRegionOptions" :key="dict.id" :label="dict.name" :value="dict.id" />
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="库位" prop="whLocationId" width="150">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.whLocationId'">
              <el-select v-model="scope.row.whLocationId" placeholder="" disabled>
                <el-option v-for="dict in scope.row.whLocationOptions" :key="dict.id" :label="dict.name" :value="dict.id" />
              </el-select>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="出库数量" prop="outQuantity" width="150">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.outQuantity'" :rules="rules.outQuantity">
              <el-input v-model.number="scope.row.outQuantity" placeholder="请输入出库数量" :disabled="form.auditStatus!='1'&&form.applyStatus!='1'?false:true" />
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="型号" prop="materialModel">
        </el-table-column>
        <el-table-column label="规格" prop="materialSpecification">
        </el-table-column>
        <el-table-column label="单位" prop="materialUnit">
        </el-table-column>
        <el-table-column label="生产批号" prop="batchNo" width="150">
          <template slot-scope="scope">
            <el-form-item :prop="'wmsOutWarehouseApplyDetailList.'+scope.$index+'.batchNo'">
              <el-input v-model="scope.row.batchNo" placeholder="" disabled />
            </el-form-item>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button v-if="form.billStatus=='1'" type="primary" @click="checkConfirm">盘点确认</el-button>
      <el-button v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="primary" @click="saveForm">保 存</el-button>
      <el-button v-if="form.auditStatus!='1'&&form.applyStatus!='1'" type="warning" @click="submitForm">提 交</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  name: "OutWarehouseDetail",
  components: {
    
  },
  data() {
    return {
      material: null,
      currentRowIndex: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedWmsOutWarehouseApplyDetail: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出库申请表格数据
      outWarehouseApplyList: [],
      // 出库申请明细表格数据
      wmsOutWarehouseApplyDetailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      materialSelectOpen: false,
      // 业务类型字典
      bizTypeOptions: [],
      // 客户字典
      customerIdOptions: [],
      // 合同类型字典
      contractTypeOptions: [],
      // 申请类型字典
      applyTypeOptions: [],
      // 申请人字典
      applyUserOptions: [],
      // 申请日期时间范围
      daterangeApplyTime: [],
      // 申请状态字典
      applyStatusOptions: [],
      // 审核人字典
      auditUserOptions: [],
      // 审核日期时间范围
      daterangeAuditTime: [],
      // 审核状态字典
      auditStatusOptions: [],
      // 单据状态字典
      billStatusOptions: [],
      warehouseIdOptions: [],
      // 查询参数
      queryParams: {
        
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
}
</script>